from PIL import Image, ImageDraw


def draw_mask(image: Image.Image,
              mask_color: tuple,
              raster_a: int,
              raster_d: int,
              index: int,
              ) -> Image.Image:
    """
    Add mask for image, leaving image unchanged and return a masked
    copy of image.

    :param image: to mask image
    :param mask_color: mask color, must match image mode
    :param raster_a: raster transparent width
    :param raster_d: raster constant
    :param index: index of mask, in [0, d//a)
    :return: a masked image
    """
    width, height = image.size
    image = image.copy()
    draw_image = ImageDraw.Draw(image)
    raster_b = raster_d - raster_a
    for to_draw_x in range(-raster_b+index*raster_a, width+raster_d+1, raster_d):
        draw_image.rectangle((to_draw_x, 0, to_draw_x+raster_b-1, height),
                             fill=mask_color,
                             width=0)
    return image
